<?php

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\ChOperationLog;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Request\RoomGroupRequest;
use App\CustHub\Service\ChRoomGroupService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

#[Controller('ch/room/group'),ApiAuth,VerifySignature]
class RoomGroupController extends BaseController
{
    #[Inject]
    protected ChRoomGroupService $service;

    /**
     * 列表
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('list')]
    public function list(): ResponseInterface
    {
        return $this->success($this->service->list($this->request->all()));
    }

    /**
     * 新增
     * @param RoomGroupRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('save'),ChOperationLog]
    public function save(RoomGroupRequest $request): ResponseInterface
    {
        return $this->success(['id'=>$this->service->save($request->all())]);
    }

    /**
     * 编辑
     * @param RoomGroupRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('update'),ChOperationLog]
    public function update(RoomGroupRequest $request): ResponseInterface
    {
        return $this->service->update($request->input('id'),$request->all()) ? $this->success() : $this->error();
    }

    /**
     * 删除
     * @param RoomGroupRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('delete'),ChOperationLog]
    public function delete(RoomGroupRequest $request): ResponseInterface
    {
        return $this->service->deleteById($request->input('id')) ? $this->success() : $this->error();
    }

    /**
     * 移动分组
     * @param RoomGroupRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('moveGroup'),ChOperationLog]
    public function moveGroup(RoomGroupRequest $request): ResponseInterface
    {
        return $this->service->moveGroup($request->all()) ? $this->success() : $this->error();
    }
}